package com.swancloud.model.compute.actions;

/**
 * Options to live-migrate a server to a new host without rebooting
 *
 * @author Jeremy Unruh
 */
public class LiveMigrateOptions extends BaseActionOptions {

    private enum Option implements OptionEnum {
        HOST("host"),
        BLOCK_MIGRATION("block_migration"),
        DISK_OVER_COMMIT("disk_over_commit"),
        FORCE("force")
        ;
        private final String param;

        private Option(String param) { this.param = param; }

        public String getParam() {
            return param;
        }
    }

    private LiveMigrateOptions() {
        super();
        add(Option.HOST, "None");
        add(Option.BLOCK_MIGRATION, false);
        add(Option.DISK_OVER_COMMIT, false);
        add(Option.FORCE, false);
    }

    public static LiveMigrateOptions create() {
        return new LiveMigrateOptions();
    }

    /**
     * Name of the new host (Optional)
     *
     * @param host the name of the new host
     * @return LiveMigrateOptions
     */
    public LiveMigrateOptions host(String host) {
        add(Option.HOST, host);
        return this;
    }

    /**
     * Block Migration
     *
     *
     * Set to True to migrate local disks by using block migration.
     * If the source or destination host uses shared storage and you set this value to True, the live migration fails.
     *
     * Migrates local disks by using block migration.
     * Set to auto which means nova will detect whether source and destination hosts on shared storage.
     * if they are on shared storage, the live-migration won’t be block migration. Otherwise the block migration will be executed.
     * Set to True, means the request will fail when the source or destination host uses shared storage.
     * Set to False means the request will fail when the source and destination hosts are not on the shared storage.
     *
     * @param blocked if true, migration is blocked
     * @return LiveMigrateOptions
     */
    public LiveMigrateOptions blockMigration(Object blocked) {
        add(Option.BLOCK_MIGRATION, blocked);
        return this;
    }

    /**
     * Set to True to enable over commit when the destination host is checked for available disk space.
     * Set to False to disable over commit. This setting affects only the libvirt virt driver
     *
     * @param enabled if enabled, disk over commit is allowed
     * @return LiveMigrateOptions
     */
    public LiveMigrateOptions diskOverCommit(boolean enabled) {
        add(Option.DISK_OVER_COMMIT, enabled);
        return this;
    }
    /**
     * Force a live-migration by not verifying the provided destination host by the scheduler.
     *
     * @param enabled if enabled, disk over commit is allowed
     * @return LiveMigrateOptions
     */
    public LiveMigrateOptions force(boolean enabled) {
        add(Option.FORCE, enabled);
        return this;
    }

    public String getHost() {
        return get(Option.HOST);
    }

    public Object getBlockMigration() {
        return get(Option.BLOCK_MIGRATION);
    }

    public boolean getDiskOverCommit() {
        return get(Option.DISK_OVER_COMMIT);
    }

    public boolean getForce() { return get(Option.FORCE); }
}
